package control;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.PriorityDTO;
import model.UserDTO;
import business.PriorityManager;
import business.UserManager;

/**
 * Servlet implementation class LoadPriorityServlet
 */
@WebServlet("/LoadPriority")
public class LoadPriorityServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}
	private void processRequest(HttpServletRequest request,
			HttpServletResponse response) {
	PriorityManager um = new PriorityManager();
	ArrayList<PriorityDTO> data = um.findAllPriorities();
	request.setAttribute("priorities", data);
	RequestDispatcher rd = request.getRequestDispatcher("/LoadPriority.jsp");
	try{
		rd.forward(request, response);
	}catch (ServletException e) {
		// TODO: handle exception
		e.printStackTrace();
	}catch (IOException e) {
		// TODO: handle exception
		e.printStackTrace();
	}

}
}
